import requests
import re

headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
}

for i in range(10):
    page = i * 25 + 1
    url = f'https://movie.douban.com/top250?start={page}&filter='

    response = requests.get(url, headers=headers)
    name_list = re.findall(r'<span class="title">(.*?)</span>', response.text)
    for name in name_list:
        if "&" in name:
            name_list.remove(name)

    for i in range(len(name_list)):
        with open('../static/豆瓣.txt', 'a', encoding='utf-8') as f:
            f.write(f'{page + i}' + '\t' + name_list[i] + '\n')
